package com.demo.dao_admin;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.demo.entity.Employee;
import com.demo.entity.ExamDTO;
import com.demo.entity.ExamDTO2;
import com.demo.entity.ExamExams;

@Repository("adminEmployeeDAO")
public interface EmployeeDAO extends JpaRepository<Employee, Long>, JpaSpecificationExecutor<Employee> {

	//解决关联查询的N+1问题，用join语句来代替N+1
	@EntityGraph(value = "Employee.all", type = EntityGraph.EntityGraphType.FETCH)
	@Query(value = "from Employee e")
	List<Employee> findAll();
	
	//查询某个部门的所有员工,用EntityGraph注解生成join代替传统的N+1
	@EntityGraph(value = "Employee.all", type = EntityGraph.EntityGraphType.FETCH)
	@Query(value = "from Employee e where e.deptId=:deptId")
	List<Employee> findAll(Integer deptId);
	
	//查询某个部门的所有员工，也可用SQL的风格，多表where等价查询 or join查询
	@Query(value = "from Employee e,Department d where e.deptId=d.id")
	List<Employee> findAll1(Integer deptId);
}